package cn.itcast.nems.studentrecord.converter;

import cn.itcast.nems.studentrecord.constant.ReferenceTypeEnum;
import cn.itcast.nems.studentrecord.dao.entity.StudentRecordTransaction;
import cn.itcast.nems.studentrecord.dto.change.StudentRecordJournalInDateChangeDTO;
import cn.itcast.nems.studentrecord.dto.studentrecord.StudentRecordTransactionCreateDTO;
import cn.itcast.nems.studentrecord.enumeration.StudentRecordTransactionStateEnum;

/**
 * author liyong
 * create: 2024-01-12 11:56:57
 **/
public class StudentRecordTransactionConverter {

    /**
     * 更具流转记录，生成冲销流转
     *
     * @param lastTransaction 流转记录
     * @return 冲销流转
     */
    public static StudentRecordTransaction convertChargeAgainst(StudentRecordTransaction lastTransaction) {
        StudentRecordTransaction chargeAgainst = new StudentRecordTransaction();
        chargeAgainst.setStudentRecordId(lastTransaction.getStudentRecordId());
        chargeAgainst.setReferenceType(lastTransaction.getReferenceType());
        chargeAgainst.setReferenceId(lastTransaction.getReferenceId());
        chargeAgainst.setReferenceLineId(lastTransaction.getReferenceLineId());
        chargeAgainst.setClazzId(lastTransaction.getClazzId());
        chargeAgainst.setClassName(lastTransaction.getClassName());
        chargeAgainst.setPhaseNumber(lastTransaction.getPhaseNumber());
        chargeAgainst.setActualAmountDue(0);
        Integer type = StudentRecordTransaction.TYPE_OUT.equals(lastTransaction.getType()) ? StudentRecordTransaction.TYPE_IN : StudentRecordTransaction.TYPE_OUT;
        chargeAgainst.setType(type);
        chargeAgainst.setBizDate(lastTransaction.getBizDate());
        chargeAgainst.setState(lastTransaction.getState());
        return chargeAgainst;
    }

    public static StudentRecordTransactionCreateDTO convertIn(StudentRecordJournalInDateChangeDTO changeDTO) {
        StudentRecordTransactionCreateDTO result = new StudentRecordTransactionCreateDTO();
        result.setStudentRecordId(changeDTO.getStudentRecordId());
        result.setReferenceType(ReferenceTypeEnum.CLAZZ_START_DATE_CHANGE);
        result.setReferenceId(changeDTO.getJournalId());
        result.setReferenceLineId(changeDTO.getJournalLineId());
        result.setClazzId(changeDTO.getClazzId());
        result.setClassName(changeDTO.getClassName());
        result.setPhaseNumber(1);
        result.setType(StudentRecordTransaction.TYPE_IN);
        result.setBizDate(changeDTO.getAfterInDate().atStartOfDay());
        result.setActualAmountDue(0);
        result.setState(StudentRecordTransactionStateEnum.VALID);
        return result;
    }
}
